#nullable enable

using PHMEE.CommonUtils;

namespace PHMEE.TDengineInfrastructure;

public class TDengineRepositoryException(
    Guid vesselId,
    DateTime? ts,
    DateTime? startDateTimeUtc,
    DateTime? endDateTimeUtc,
    string message,
    Exception? innerException = null)
    : Exception(message, innerException)
{
    // 需要记录的属性
    private Guid VesselId { get; } = vesselId;
    private DateTime? Ts { get; } = ts;
    private DateTime? StartDateTimeUtc { get; } = startDateTimeUtc;
    private DateTime? EndDateTimeUtc { get; } = endDateTimeUtc;

    // 通过构造函数初始化异常的所有信息

    // 重写 ToString 方法，提供更详细的错误信息
    public override string ToString()
    {
        return $"TDengineRepositoryException: VesselId: {VesselId}, " +
               $"Ts: {(Ts.HasValue ? Ts.Value.ToFormattedUtcString(): "N/A")}, " +
               $"StartDateTimeUtc: {(StartDateTimeUtc.HasValue ? StartDateTimeUtc.Value.ToFormattedUtcString() : "N/A")}, " +
               $"EndDateTimeUtc: {(EndDateTimeUtc.HasValue ? EndDateTimeUtc.Value.ToFormattedUtcString() : "N/A")}, " +
               $"Message: {Message}";
    }
}